//
//  PPHomeDotView.m
//  pickpic
//
//  Created by Jinxiao on 10/30/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPHomeDotView.h"

@interface PPHomeDotView ()
@property (readwrite, nonatomic, strong) UIImageView *dynamicView;
@property (readwrite, nonatomic, strong) UIView *staticView;
@end

@implementation PPHomeDotView

- (instancetype)init {
    self = [super init];

//    NSURL *GIFURL = [[NSBundle mainBundle] URLForResource:@"dot" withExtension:@"gif"];

    _dynamicView = [[UIImageView alloc] init];
//    _dynamicView.backgroundColor = [UIColor clearColor];
    _dynamicView.hidden = YES;
//    [_dynamicView sd_setImageWithURL:GIFURL];
    _dynamicView.backgroundColor = RED;
    _dynamicView.layer.cornerRadius =  4;
    _dynamicView.layer.masksToBounds = YES;
    [self addSubview:_dynamicView];

    _staticView = [[UIView alloc] init];
//    _staticView.backgroundColor = [UIColor colorWithRGBHex:0xff3a2f];
    _staticView.backgroundColor = RED;
    _staticView.layer.cornerRadius = 3;
    _staticView.layer.masksToBounds = YES;
    _staticView.hidden = YES;
    [self addSubview:_staticView];

    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    _dynamicView.frame = self.bounds;

    _staticView.frame = CGRectMake((self.width - 6)/2, (self.height - 6)/2, 6, 6);
}

- (void)displayIfNeeded {
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"DynamicDotDisplayed"]) {
        _dynamicView.hidden = NO;
        _staticView.hidden = YES;

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"DynamicDotDisplayed"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    } else {
        _dynamicView.hidden = YES;
        _staticView.hidden = NO;
    }
}

- (void)dismiss {
    _dynamicView.hidden = YES;
    _staticView.hidden = YES;
}

@end
